<template>
  <div v-loading="loading">
    <OperateCommon :showBack="true" @back="goBack">
      <template #operate>
        <template v-if="type == 0">
          <el-button
            type="primary"
            :disabled="form.status > 1"
            @click="save(0)"
          >
            暂存
          </el-button>
          <el-button
            type="primary"
            :disabled="form.status > 1"
            @click="save(10)"
            >上报</el-button
          >
        </template>
        <template v-if="type == 1">
          <el-button
            type="success"
            :disabled="reviewCheck()"
            @click="review(20)"
          >
            通过
          </el-button>
          <el-button type="danger" :disabled="reviewCheck()" @click="review(1)">
            退回
          </el-button>
        </template>
        <template v-if="type == 999">
          <el-button type="danger" @click="save(999)">修改</el-button>
        </template>
      </template>
    </OperateCommon>
    <div v-if="form.status >= 10" class="report-item">
      <div><b> 上报人：</b>{{ form.create_user_name || "无记录" }}</div>
      <div><b>上报时间：</b>{{ form.create_time || "无记录" }}</div>
    </div>
    <el-collapse
      style="margin-bottom: 10px"
      v-if="form.status > 0"
      v-model="activeNames"
      :accordion="false"
    >
      <el-collapse-item title="审核记录" :name="1">
        <el-steps align-center>
          <el-step
            title="发改局初审"
            description=""
            :status="form.first_trial1 == 1 ? 'success' : 'wait'"
          ></el-step>
          <el-step
            title="财政局初审"
            description=""
            :status="form.first_trial2 == 1 ? 'success' : 'wait'"
          ></el-step>
          <el-step
            v-if="isReviewUnite('自规局')"
            title="自规局初审"
            description=""
            :status="form.first_trial3 == 1 ? 'success' : 'wait'"
          ></el-step>
        </el-steps>
        <el-alert
          style="margin-bottom: 5px"
          v-for="item in form.fastTrialList"
          :key="item.id"
          :title="'审核时间：' + item.opdate + '【' + item.dept_name + '】'"
          type="error"
          effect="light"
          :show-icon="true"
          :closable="false"
        >
          退回原因： {{ item.opinion || "无" }}
        </el-alert>
      </el-collapse-item>
    </el-collapse>
    <el-form
      :model="form"
      ref="form"
      :rules="rules"
      label-width="130px"
      :inline="false"
      :disabled="allowEdit()"
    >
      <!-- <div class="d-model full-box padding-box shadow-box">
        <label>终审信息</label>
      </div>
      <div class="d-model full-box padding-box shadow-box">
        <label>初审信息</label>
      </div> -->
      <div class="d-model full-box padding-box shadow-box">
        <label>项目基本信息</label>
        <div class="d-row">
          <el-form-item label="申报年份" prop="plan_year">
            <el-date-picker
              v-model="form.plan_year"
              type="year"
              value-format="yyyy"
              placeholder="选择申报年份"
            >
            </el-date-picker>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item label="项目名称" prop="project_name">
            <el-select
              style="width: 600px"
              v-model="form.project_name"
              value-key=""
              placeholder="选择的计划默认续建，输入的计划默认新建"
              allow-create
              clearable
              filterable
              @change="projectChange"
            >
              <el-option
                v-for="item in historyPlan"
                :key="item.id"
                :label="item.project_name"
                :value="item.project_name"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目统一代码" prop="project_code">
            <el-input
              style="width: 300px"
              v-model="form.project_code"
              placeholder=""
            ></el-input>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item label="投资分类" prop="invest_type">
            <el-select v-model="form.invest_type" value-key="">
              <el-option label="政府投资" value="政府投资"></el-option>
              <el-option label="国企投资" value="国企投资"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="建设性质" prop="build_kind">
            <el-select v-model="form.build_kind" value-key="">
              <el-option label="前期" value="前期"></el-option>
              <el-option label="新建" value="新建"></el-option>
              <el-option label="续建" value="续建"></el-option>
              <el-option label="运维" value="运维"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="行业分类" prop="industry_type">
            <el-select v-model="form.industry_type" value-key="">
              <el-option
                v-for="item in industryOptions"
                :key="item.id"
                :label="item.dict_value"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="行业子分类" prop="industry_sub_type">
            <el-select v-model="form.industry_sub_type" value-key="">
            </el-select>
          </el-form-item> -->
        </div>
        <div v-if="form.build_kind != '运维'">
          <div class="d-row" v-if="form.build_kind != '前期'">
            <div class="d-row-child">
              <el-form-item label="计划开工时间" prop="plan_start_date">
                <el-date-picker
                  v-model="form.plan_start_date"
                  type="date"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="计划竣工时间" prop="plan_end_date">
                <el-date-picker
                  v-model="form.plan_end_date"
                  type="date"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <!-- <div class="d-row-child" v-if="form.build_kind != '新建'">
              <el-form-item label="实际开工时间" prop="fact_start_date">
                <el-date-picker
                  v-model="form.fact_start_date"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :disabled="form.build_kind == '续建' ? false : true"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item label="实际竣工时间" prop="fact_end_date">
                <el-date-picker
                  v-model="form.fact_end_date"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :disabled="form.build_kind == '续建' ? false : true"
                >
                </el-date-picker>
              </el-form-item>
            </div> -->
          </div>

          <div class="d-row">
            <el-form-item label="建设地址" prop="project_address">
              <el-input
                style="width: 800px"
                v-model="form.project_address"
              ></el-input>
            </el-form-item>
            <div class="d-row-child">
              <el-form-item label="建设用地" prop="land_area">
                <el-input-number
                  v-model="form.land_area"
                  :min="0"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                >
                </el-input-number>
                <span>（ 亩 ）</span>
              </el-form-item>
              <el-form-item label="新需用地面积" prop="plan_land_area">
                <el-input-number
                  v-model="form.plan_land_area"
                  :min="0"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                >
                </el-input-number>
                <span>（ 亩 ）</span>
              </el-form-item>
              <el-form-item label="拆迁面积" prop="plan_demolition_area">
                <el-input-number
                  v-model="form.plan_demolition_area"
                  :min="0"
                  :step="1"
                  :precision="2"
                  :controls="true"
                  controls-position="right"
                >
                </el-input-number>
                <span>（ 平方米 ）</span>
              </el-form-item>
            </div>
            <!-- <el-form-item label="需农转用保留" prop="paln_trans_area">
              <el-input-number
                v-model="form.paln_trans_area"
                :min="0"
                :step="1"
                :precision="2"
                :controls="true"
                controls-position="right"
              >
              </el-input-number>
              <span>（ 亩 ）</span>
            </el-form-item> -->
          </div>
        </div>

        <div v-if="form.build_kind != '运维'">
          <div class="d-row">
            <el-form-item
              class="d-textarea"
              label="建设规模及内容"
              label-width="200"
              prop="project_content"
            >
              <el-input
                type="textarea"
                v-model="form.project_content"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
                placeholder="请尽量控制在150字左右"
              ></el-input>
            </el-form-item>
          </div>
          <div class="d-row" v-if="form.build_kind != '续建'">
            <el-form-item
              class="d-textarea"
              label="建设必要性"
              label-width="200"
              prop="project_necessity"
            >
              <el-input
                type="textarea"
                v-model="form.project_necessity"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
          </div>
          <div class="d-row">
            <el-form-item
              class="d-textarea"
              label="规划名称和文号"
              label-width="200"
              prop="planning_name"
            >
              <el-input
                type="textarea"
                v-model="form.planning_name"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
          </div>
          <div class="d-row">
            <el-form-item
              class="d-textarea"
              label="当年形象进度"
              label-width="200"
              prop="plan_content"
            >
              <el-input
                type="textarea"
                v-model="form.plan_content"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
          </div>
        </div>
        <div v-if="form.build_kind == '运维'">
          <div class="d-row">
            <el-form-item
              class="d-textarea"
              label="运维内容"
              label-width="200"
              prop="project_content"
            >
              <el-input
                type="textarea"
                v-model="form.project_content"
                :autosize="{
                  minRows: 3,
                  maxRows: 6,
                }"
              ></el-input>
            </el-form-item>
          </div>
          <div class="d-row">
            <el-form-item label="运维单位" prop="owner_id">
              <DeptCascader
                :options="deptOptions"
                :defaultChecked.sync="form.owner_id"
                @change="changeDept"
              ></DeptCascader>
            </el-form-item>
            <el-form-item label="实施时间" prop="plan_start_date">
              <el-date-picker
                v-model="form.plan_start_date"
                type="date"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </div>
        </div>
      </div>
      <div class="d-model full-box padding-box shadow-box">
        <label>投资情况</label>
        <!-- 总投资 -->
        <div class="d-row" v-if="calcInvestmentType('all')">
          <div class="d-row-child count-bg">
            <el-form-item label-width="200px" label="总投资" prop="investment">
              <el-input-number
                v-model="form.investment"
                :min="0"
                :step="1"
                :precision="2"
                :controls="true"
                controls-position="right"
                disabled
              >
              </el-input-number>
              <span>（ 万元 ）</span>
            </el-form-item>
          </div>
          <el-form-item label="上级财政" prop="investment_superior">
            <el-input-number
              v-model="form.investment_superior"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcAll"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="市级财政" prop="investment_finance">
            <el-input-number
              v-model="form.investment_finance"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcAll"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="自筹" prop="investment_self">
            <el-input-number
              v-model="form.investment_self"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcAll"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="其他" prop="investment_other">
            <el-input-number
              v-model="form.investment_other"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcAll"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
        </div>
        <!-- 本年完成投资 -->
        <div class="d-row" v-if="calcInvestmentType('finish')">
          <div class="d-row-child count-bg">
            <el-form-item
              label-width="200px"
              :label="`至${form.plan_year - 1}年底累计完成投资`"
              prop="finish_investment"
            >
              <el-input-number
                v-model="form.finish_investment"
                :min="0"
                :step="1"
                :precision="2"
                :controls="true"
                controls-position="right"
                disabled
              >
              </el-input-number>
              <span>（ 万元 ）</span>
            </el-form-item>
          </div>
          <el-form-item label="上级财政" prop="finish_investment_superior">
            <el-input-number
              v-model="form.finish_investment_superior"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcFinish"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="市级财政" prop="finish_investment_finance">
            <el-input-number
              v-model="form.finish_investment_finance"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcFinish"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="自筹" prop="finish_investment_self">
            <el-input-number
              v-model="form.finish_investment_self"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcFinish"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="其他" prop="finish_investment_other">
            <el-input-number
              v-model="form.finish_investment_other"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcFinish"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
        </div>
        <!-- 明年计划投资 -->
        <div class="d-row" v-if="calcInvestmentType('plan')">
          <div class="d-row-child count-bg">
            <el-form-item
              label-width="200px"
              :label="`${form.plan_year}年投资计划`"
              prop="plan_investment"
            >
              <el-input-number
                v-model="form.plan_investment"
                :min="0"
                :step="1"
                :precision="2"
                :controls="true"
                controls-position="right"
              >
              </el-input-number>
              <span>（ 万元 ）</span>
            </el-form-item>
          </div>
          <div class="d-row-child">
            <el-form-item :label="`财务数`" prop="">
              <el-input-number
                v-model="plan_investement"
                :min="0"
                :step="1"
                :precision="2"
                :controls="true"
                controls-position="right"
                disabled
              >
              </el-input-number>
              <span>（ 万元 ）</span>
            </el-form-item>
          </div>
          <el-form-item label="上级财政" prop="plan_investment_superior">
            <el-input-number
              v-model="form.plan_investment_superior"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcPlan"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="市级财政" prop="plan_investment_finance">
            <el-input-number
              v-model="form.plan_investment_finance"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcPlan"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="自筹" prop="plan_investment_self">
            <el-input-number
              v-model="form.plan_investment_self"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcPlan"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
          <el-form-item label="其他" prop="plan_investment_other">
            <el-input-number
              v-model="form.plan_investment_other"
              :min="0"
              :step="1"
              :precision="2"
              :controls="true"
              controls-position="right"
              @change="calcPlan"
            >
            </el-input-number>
            <span>（ 万元 ）</span>
          </el-form-item>
        </div>
      </div>
      <div
        v-if="form.build_kind != '运维'"
        class="d-model full-box padding-box shadow-box"
      >
        <label>相关人员单位</label>
        <div class="d-row">
          <el-form-item label="建设单位" prop="owner_id">
            <DeptCascader
              :options="deptOptions"
              :defaultChecked.sync="form.owner_id"
              @change="changeDept"
            ></DeptCascader>
          </el-form-item>
          <el-form-item label="责任单位" prop="responsible_unit_id">
            <!-- <el-input
              v-model="form.responsible_unit_name"
              placeholder=""
              :disabled="type != 999"
            ></el-input> -->
            <DeptCascader
              :options="deptOptions"
              :defaultChecked.sync="form.responsible_unit_id"
              :disabled="type != 999"
              @change="changeDeptResponse"
            ></DeptCascader>
          </el-form-item>
          <el-form-item label="项目联系人" prop="responsible_leader">
            <el-input
              style="width: 217px"
              v-model="form.responsible_leader"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人电话" prop="responsible_linkman_phone">
            <el-input v-model="form.responsible_linkman_phone"> </el-input>
          </el-form-item>
        </div>
      </div>
      <div
        v-if="form.build_kind != '运维'"
        class="d-model full-box padding-box shadow-box"
      >
        <label>前期工作情况</label>
        <div class="d-row">
          <el-form-item
            label="项目备案"
            label-width="250px"
            size="normal"
            prop="work1_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work1_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work1')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work1_status == '2'"
                prop="preliminary_work1"
              >
                <el-date-picker
                  v-model="form.preliminary_work1"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work1_status == '1'"
                prop="preliminary_work1"
              >
                <el-input
                  v-model="form.preliminary_work1"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="项目建议书批复"
            label-width="250px"
            size="normal"
            prop="work2_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work2_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work2')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work2_status == '2'"
                prop="preliminary_work2"
              >
                <el-date-picker
                  v-model="form.preliminary_work2"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work2_status == '1'"
                prop="preliminary_work2"
              >
                <el-input
                  v-model="form.preliminary_work2"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="申请报告核准批复"
            label-width="250px"
            size="normal"
            prop="work3_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work3_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work3')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work3_status == '2'"
                prop="preliminary_work3"
              >
                <el-date-picker
                  v-model="form.preliminary_work3"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work3_status == '1'"
                prop="preliminary_work3"
              >
                <el-input
                  v-model="form.preliminary_work3"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="可研报告批复"
            label-width="250px"
            size="normal"
            prop="work4_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work4_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work4')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work4_status == '2'"
                prop="preliminary_work4"
              >
                <el-date-picker
                  v-model="form.preliminary_work4"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work4_status == '1'"
                prop="preliminary_work4"
              >
                <el-input
                  v-model="form.preliminary_work4"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="初步设计批复"
            label-width="250px"
            size="normal"
            prop="work5_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work5_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work5')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work5_status == '2'"
                prop="preliminary_work5"
              >
                <el-date-picker
                  v-model="form.preliminary_work5"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work5_status == '1'"
                prop="preliminary_work5"
              >
                <el-input
                  v-model="form.preliminary_work5"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="建设项目用地预审与选址意见"
            label-width="250px"
            size="normal"
            prop="work6_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work6_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work6')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work6_status == '2'"
                prop="preliminary_work6"
              >
                <el-date-picker
                  v-model="form.preliminary_work6"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work6_status == '1'"
                prop="preliminary_work6"
              >
                <el-input
                  v-model="form.preliminary_work6"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="用地规划许可"
            label-width="250px"
            size="normal"
            prop="work7_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work7_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work7')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work7_status == '2'"
                prop="preliminary_work7"
              >
                <el-date-picker
                  v-model="form.preliminary_work7"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work7_status == '1'"
                prop="preliminary_work7"
              >
                <el-input
                  v-model="form.preliminary_work7"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="环境影响评价批复"
            label-width="250px"
            size="normal"
            prop="work8_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work8_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work8')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work8_status == '2'"
                prop="preliminary_work8"
              >
                <el-date-picker
                  v-model="form.preliminary_work8"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work8_status == '1'"
                prop="preliminary_work8"
              >
                <el-input
                  v-model="form.preliminary_work8"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
        <div class="d-row">
          <el-form-item
            label="节能评估和审查"
            label-width="250px"
            size="normal"
            prop="work9_status"
          >
            <el-select
              style="width: 150px"
              v-model="form.work9_status"
              placeholder="请选择完成情况"
              clearable
              @change="fwsChange('preliminary_work9')"
            >
              <el-option label="已完成" value="1"></el-option>
              <el-option label="未完成" value="2"></el-option>
              <el-option label="不涉及" value="3"></el-option>
            </el-select>
            <div style="display: inline-block; margin-left: 10px">
              <el-form-item
                v-if="form.work9_status == '2'"
                prop="preliminary_work9"
              >
                <el-date-picker
                  v-model="form.preliminary_work9"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="计划完成时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                v-if="form.work9_status == '1'"
                prop="preliminary_work9"
              >
                <el-input
                  v-model="form.preliminary_work9"
                  placeholder="批复文号"
                ></el-input>
              </el-form-item>
            </div>
          </el-form-item>
        </div>
      </div>
    </el-form>
    <el-dialog
      title="退回原因"
      width="600px"
      :visible.sync="dialog.rejectReason"
      :close-on-click-modal="false"
      @close="dialog.rejectReason = false"
    >
      <div>
        <el-input
          type="textarea"
          v-model="rejectReason"
          :autosize="{
            minRows: 3,
            maxRows: 6,
          }"
          placeholder="请输入退回原因"
        ></el-input>
      </div>
      <span slot="footer">
        <el-button @click="dialog.rejectReason = false">取消</el-button>
        <el-button type="danger" @click="reject">退回</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import OperateCommon from "@/components/Common/OperateCommon.vue";
import LinkTo from "@/mixins/LinkTo";
import {
  getHisyoryYearPlanList,
  getIndustry,
  getYearPlanDetails,
  postYearPlanReview,
  postYearPlanSave,
} from "@/api/YearPlan/Index";
import { required } from "@/utils/eValidate";
import DeptCascader from "@/components/Common/DeptCascader.vue";
import { getDeptTree } from "@/api/System/Department";
import CommonUpload from "@/components/Common/CommonUpload.vue";
import uploadMixin from "@/components/GenerateForm/uploadMixin";
import { debounce } from "@/utils/debounce";
import Big from "big.js";
export default {
  name: "YearPlanDeclareForm",
  mixins: [LinkTo, uploadMixin],
  components: { OperateCommon, DeptCascader, CommonUpload },
  data() {
    return {
      loading: false,
      id: 0,
      type: 0,
      form: JSON.parse(JSON.stringify(form)),
      rules: {
        plan_year: [required],

        project_name: [required],
        project_code: [],

        project_type: [required],
        invest_type: [required],
        industry_type: [required],
        industry_sub_type: [required],
        build_kind: [required],

        plan_start_date: [required],
        plan_end_date: [required],

        fact_start_date: [],
        fact_end_date: [],

        project_address: [required],
        land_area: [required],

        project_content: [required],
        project_necessity: [required],
        plan_content: [required],
        planning_name: [required],

        leader_id: [required],
        owner_representative_id: [required],
        owner_representative_name: [required],

        responsible_leader: [required],

        owner_id: [required],
        regulator_dept_id: [required],
        responsible_unit_id: [required],

        work1_status: [required],
        work2_status: [required],
        work3_status: [required],
        work4_status: [required],
        work5_status: [required],
        work6_status: [required],
        work7_status: [required],
        work8_status: [required],
        work9_status: [required],

        preliminary_work1: [required],
        preliminary_work2: [required],
        preliminary_work3: [required],
        preliminary_work4: [required],
        preliminary_work5: [required],
        preliminary_work6: [required],
        preliminary_work7: [required],
        preliminary_work8: [required],
        preliminary_work9: [required],
      },
      historyPlan: [],
      user: JSON.parse(localStorage.getItem("user")),
      industryOptions: [],
      deptOptions: [],

      dialog: {
        rejectReason: false,
      },
      rejectReason: "",
      activeNames: 1,

      plan_investement: "",
    };
  },
  methods: {
    debounce,
    save(status) {
      if (this.type == 999) {
        // 任意编辑
        postYearPlanSave(this.form).then((res) => {
          delete this.form.create_user_name;
          delete this.form.create_time;

          if (res.code == 0) {
            this.checkFile(res.data);
            this.$message.success("修改成功");
            this.goBack();
          }
        });
      } else {
        // 正常流程
        if (status == 0) {
          if (this.form.project_name.trim() == "") {
            this.$message.error("无【项目名称】禁止暂存");
            return;
          }
          this.form.status = 0;
          this.form.status_text = "暂存";
          postYearPlanSave(this.form).then((res) => {
            if (res.code == 0) {
              this.checkFile(res.data);
              this.$message.success("暂存成功");
              this.goBack();
            }
          });
        }
        if (status == 10) {
          this.$refs.form.validate((valid) => {
            if (valid) {
              this.form.status = 10;
              this.form.status_text = "待审核";
              postYearPlanSave(this.form).then((res) => {
                if (res.code == 0) {
                  this.checkFile(res.data);
                  this.$message.success("上报成功");
                  this.goBack();
                }
              });
            }
          });
        }
      }
    },
    review(status) {
      if (status == 1) {
        this.dialog.rejectReason = true;
      }
      if (status == 20) {
        this.$confirm("确定通过当前计划吗", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "success",
        })
          .then(() => {
            this.pass();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
    },
    pass() {
      postYearPlanReview({
        id: this.form.id,
        opinion: "",
        status: 1,
      }).then((res) => {
        if (res.code == 0) {
          this.$message.success("审核通过成功");
          this.goBack();
        }
      });
    },
    reject() {
      postYearPlanReview({
        id: this.form.id,
        opinion: this.rejectReason,
        status: 2,
      }).then((res) => {
        if (res.code == 0) {
          this.$message.success("审核退回成功");
          this.goBack();
        }
      });
    },
    goBack() {
      switch (parseInt(this.type)) {
        case 0:
          this.linkTo(`/declare`);
          break;
        case 1:
          this.linkTo(`/firstReview`);
          break;
        case 2:
          this.linkTo(`/planRelease`);
          break;
        case 999:
          this.linkTo(`/bmYearPlan`);
          break;
        default:
          break;
      }
    },
    changeDept(val) {
      this.form.owner_id = val.value;
      this.form.owner_name = val.label;
    },
    changeDeptResponse(val) {
      this.form.responsible_unit_id = val.value;
      this.form.responsible_unit_name = val.label;
    },
    initOptions() {
      this.form.owner_id = this.user.dept_id;
      this.form.owner_name = this.user.dept_name;

      this.form.create_user_name = this.user.user_name;

      this.form.responsible_unit_id = this.user.dept_id;
      this.form.responsible_unit_name = this.user.dept_name;

      if (this.type == 999) {
        this.rules = null;
      }

      getIndustry().then((res) => {
        if (res.code == 0) {
          this.industryOptions = res.data;
        }
      });
      getDeptTree().then((res) => {
        if (res.code == 0) {
          this.deptOptions = res.data;
        }
      });
    },
    initHistoryPlan() {
      this.loading = true;
      getHisyoryYearPlanList().then((res) => {
        if (res.code == 0) {
          this.historyPlan = res.data;
          this.loading = false;
        }
      });
    },
    initData() {
      this.loading = true;
      getYearPlanDetails({ id: this.id }).then((res) => {
        if (res.code == 0) {
          this.form = res.data;
          this.loading = false;
        }
      });
    },
    projectChange: debounce(function (val) {
      let current = this.historyPlan.filter((i) => {
        return i.project_name.trim() == val.trim();
      })[0];

      if (current) {
        this.form = Object.assign(this.form, current);
        this.form.status = 0;
        this.form.status_text = "";

        delete this.form.id;

        this.form.plan_year = new Date().getFullYear() + 1 + "";
      } else {
        // this.form = JSON.parse(JSON.stringify(form));
      }
    }, 300),

    reviewCheck() {
      /**
       * 26 发改
       * 33 财政
       * 35 自规
       */
      let dept_id = JSON.parse(localStorage.getItem("user")).dept_id;

      let status = true;

      switch (parseInt(dept_id)) {
        case 26:
          if (this.form.first_trial1 == 0) {
            status = false;
          }
          break;
        case 33:
          if (this.form.first_trial2 == 0) {
            status = false;
          }
          break;
        case 35:
          if (this.form.first_trial3 == 0) {
            if (this.form.build_kind == "新建") {
              status = true;
              break;
            }
            if (this.form.build_kind == "续建") {
              status = true;
              break;
            }
            status = false;
          }
          break;
        default:
          status = true;
      }

      return status;
    },
    allowEdit() {
      switch (parseInt(this.type)) {
        case 0:
        case 1:
        case 2:
          if (this.form.status >= 10) {
            return true;
          }
        case 999:
          return false;
        default:
          return false;
      }
    },
    calcAll() {
      this.form.investment = new Big(this.form.investment_finance)
        .plus(new Big(this.form.investment_superior))
        .plus(new Big(this.form.investment_self))
        .plus(new Big(this.form.investment_other));
    },
    calcFinish() {
      this.form.finish_investment = new Big(this.form.finish_investment_finance)
        .plus(new Big(this.form.finish_investment_superior))
        .plus(new Big(this.form.finish_investment_self))
        .plus(new Big(this.form.finish_investment_other));
    },
    calcPlan() {
      this.plan_investement = new Big(this.form.plan_investment_finance)
        .plus(new Big(this.form.plan_investment_superior))
        .plus(new Big(this.form.plan_investment_self))
        .plus(new Big(this.form.plan_investment_other));
    },
    calcInvestmentType(type) {
      switch (type) {
        case "all":
          return true;
        case "finish":
          if (this.form.invest_type == "政府投资") {
            if (this.form.build_kind == "前期") {
              return false;
            }
            if (this.form.build_kind == "新建") {
              return false;
            }
            if (this.form.build_kind == "续建") {
              return true;
            }
            if (this.form.build_kind == "运维") {
              return false;
            }
          }

          if (this.form.invest_type == "国企投资") {
            if (this.form.build_kind == "前期") {
              return false;
            }
            if (this.form.build_kind == "新建") {
              return false;
            }
            if (this.form.build_kind == "续建") {
              return true;
            }
            if (this.form.build_kind == "运维") {
              return false;
            }
          }
        case "plan":
          if (this.form.invest_type == "政府投资") {
            if (this.form.build_kind == "前期") {
              return false;
            }
            if (this.form.build_kind == "新建") {
              return true;
            }
            if (this.form.build_kind == "续建") {
              return true;
            }
            if (this.form.build_kind == "运维") {
              return true;
            }
          }

          if (this.form.invest_type == "国企投资") {
            if (this.form.build_kind == "前期") {
              return false;
            }
            if (this.form.build_kind == "新建") {
              return true;
            }
            if (this.form.build_kind == "续建") {
              return true;
            }
            if (this.form.build_kind == "运维") {
              return true;
            }
          }

        default:
          break;
      }
    },
    fwsChange(type) {
      this.$refs.form.clearValidate(type);
    },
    isReviewUnite(type) {
      switch (type) {
        case "自规局":
          if (this.form.build_kind == "新建") {
            return true;
          }
          if (this.form.build_kind == "前期") {
            return true;
          }
        default:
          return false;
      }
    },
  },
  created() {
    this.id = this.$route.params.id;
    this.type = this.$route.params.type;

    this.initOptions();

    if (this.id == 0) {
      // 新建
      this.initHistoryPlan();
    } else {
      this.initData();
    }
  },
  watch: {
    "form.invest_type"() {
      this.calcInvestmentType("all");
      this.calcInvestmentType("finish");
      this.calcInvestmentType("plan");
    },
    "form.build_kind"() {
      this.calcInvestmentType("all");
      this.calcInvestmentType("finish");
      this.calcInvestmentType("plan");
    },
  },
};

const form = {
  plan_year: new Date().getFullYear() + 1 + "", // 计划年份

  project_name: "", // 项目名称
  project_code: "", // 项目编码

  project_type: "", // 项目分类
  build_kind: "新建", // 建设性质
  invest_type: "", // 投资类型
  industry_type: "", // 行业分类 数据字典
  // industry_sub_type: "", // 行业子分类

  plan_start_date: "", // 计划开工时间
  plan_end_date: "", // 计划竣工时间

  // fact_start_date: "", // 实际开工时间
  // fact_end_date: "", // 实际竣工时间

  project_address: "", // 建设地址
  land_area: "", // 建设用地
  plan_land_area: "", // 本年计划用地
  paln_trans_area: "", // 需农转用
  plan_demolition_area: "", // 计划征迁用地

  project_content: "", // 建设规模及内容
  plan_content: "", // 年度形象进度
  project_necessity: "", // 建设必要性
  planning_name: "", // 规划名称和文号

  investment: "", // 总投资
  investment_finance: "", // 市级财政金额
  investment_superior: "", // 上级财政金额
  investment_self: "", // 自筹
  investment_other: "", // 其他

  plan_investment: "", // 计划总投资
  plan_investment_finance: "", // 计划市级财政金额
  plan_investment_superior: "", // 计划上级财政金额
  plan_investment_self: "", // 计划自筹
  plan_investment_other: "", // 计划其他

  finish_investment: "", // 完成总投资
  finish_investment_finance: "", // 完成市级财政金额
  finish_investment_superior: "", // 完成上级财政金额
  finish_investment_self: "", //	完成自筹
  finish_investment_other: "", // 完成其他

  owner_representative_id: "", // 业主代表身份证号
  owner_representative_name: "", // 业主代表姓名

  owner_id: "", // 建设单位 id
  owner_name: "", // 建设单位

  cooperate_unit: "", // 项目配合单位

  regulator_dept_id: "", // 行业主管部门id
  regulator_dept_name: "", // 行业主管部门

  responsible_leader: "", // 责任领导

  responsible_unit_id: "", // 责任单位id
  responsible_unit_name: "", // 责任单位

  responsible_linkman: "", // 责任人
  responsible_linkman_phone: "", // 责任人电话

  create_user_name: "", // 申报人
  create_dept_name: "", // 申报人 所在部门
  update_time: "", // 最后更新时间

  // 状态编号 0、10、15、20、25、30、100
  status: "",
  // 状态 保存、申报、初审退回、初审、市领导审核退回、市领导审核、前期报批、计划下达
  status_text: "",

  first_trial1: "", // 发改局初审0未审核1通过2不通过
  first_trial2: "", // 财政局初审0未审核1通过2不通过
  first_trial3: "", // 自归局初审0未审核1通过2不通过

  remark: "", // 备注

  // 1 完成 2 未完成 3不涉及
  work1_status: "",
  work2_status: "",
  work3_status: "",
  work4_status: "",
  work5_status: "",
  work6_status: "",
  work7_status: "",
  work8_status: "",
  work9_status: "",

  preliminary_work1: "",
  preliminary_work2: "",
  preliminary_work3: "",
  preliminary_work4: "",
  preliminary_work5: "",
  preliminary_work6: "",
  preliminary_work7: "",
  preliminary_work8: "",
  preliminary_work9: "",
};
</script>

<style lang="scss" scoped>
.d-model {
  margin-bottom: 10px;
  font-weight: 600;
}
.d-row {
  margin: 20px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid #eee;
  > :deep(.el-form-item) {
    margin-bottom: 20px;
    > div {
      > :deep(.el-form-item) {
        margin-bottom: 0px;
      }
    }
  }
}
.d-row-child {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.d-textarea {
  width: 92%;
  margin: 0 auto;
}

.count-bg {
  margin: 20px 0;
  background-color: rgb(140, 197, 255);
  display: flex;
  align-items: center;
  :deep(.el-form-item__label) {
    color: #000;
    font-weight: 600;
  }
  :deep(.el-form-item) {
    margin: 10px 0;
  }
}
.report-item {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  > div {
    &:nth-child(1) {
      margin-right: 20px;
    }
  }
}
</style>
